package com.kongge.viewdisplayframeworklib.sdk;

import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;

import com.kongge.viewdisplayframeworklib.R;
import com.kongge.viewdisplayframeworklib.control.PublicInterface;
import com.kongge.viewdisplayframeworklib.model.LayoutIdFactory;

/**
 * Created by kongge on 2017/11/17.
 * description:
 * layoutid:
 */
public class SDKProxy implements LifeCircleInter{

    private static SDKProxy instance;
    private LifeCircleInter proxyObj;

    private SDKProxy() {

    }

    public static SDKProxy getInstance() {
        if (instance == null) {
            synchronized (SDKProxy.class) {
                if (instance == null) {
                    instance = new SDKProxy();
                }
            }
        }
        return instance;
    }

    public void init(Context context,String configFilePath) {
        if (proxyObj != null) {
            return;
        }
        proxyObj = (LifeCircleInter) LayoutInflater.from(context).inflate(R.layout.view_display_hexin_view, null);
        PublicInterface.setConfigFilePath(configFilePath);
    }

    public void setOnSDKExitListener(OnSDKExitListener listener) {
        PublicInterface.setSdkExitListener(listener);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        if (proxyObj != null) {
            proxyObj.onCreate(savedInstanceState);
        }
    }

    @Override
    public void onDestroy() {
        if (proxyObj != null) {
            proxyObj.onDestroy();
            PublicInterface.setSdkExitListener(null);
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (proxyObj != null) {
            return proxyObj.onKeyDown(keyCode, event);
        }
        return false;
    }

    @Override
    public void onTabBarClick(int oldIndex, int newIndex) {
        if (proxyObj != null) {
            proxyObj.onTabBarClick(oldIndex, newIndex);
        }
    }

    @Override
    public void onScreenConfigurationChanged(Configuration newConfig) {
        if (proxyObj != null) {
            proxyObj.onScreenConfigurationChanged(newConfig);
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (proxyObj != null) {
            proxyObj.onActivityResult(requestCode, resultCode, data);
        }
    }

    @Override
    public void onStart() {
        if (proxyObj != null) {
            proxyObj.onStart();
        }
    }

    @Override
    public void onRestart() {
        if (proxyObj != null) {
            proxyObj.onRestart();
        }
    }

    @Override
    public void onResume() {
        if (proxyObj != null) {
            proxyObj.onResume();
        }
    }

    @Override
    public void onPause() {
        if (proxyObj != null) {
            proxyObj.onPause();
        }
    }

    @Override
    public void onStop() {
        if (proxyObj != null) {
            proxyObj.onStop();
        }
    }

    public View getHexinView() {
        return (View) proxyObj;
    }
}
